from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d):
        super().__init__(d)

    def play_only_1(self):
        return True

    def get_name(self):
        return "小鸡舰队出击"

    def check_done(self, throw=True):
        return False

    def select(self):
        """
        选择操作
        :return:
        """
        index = 0
        w, h = self.d.window_size()
        while self.img_exit('./game/img/小鸡舰队出击/select.png', 5):
            if index >= 20:
                break
            self.log_msg("需要选择卡片")
            self.log_msg("点击选择卡片")
            self.d.click(w / 2, h / 2)
            self.d.sleep(1.5)

            index += 1

    def game_alert(self):
        self.alert_close_by_file('./game/img/小鸡舰队出击')

    def handle_main(self):
        self.log_msg("等待进入游戏主界面")
        self.img_exit('./game/img/小鸡舰队出击/game_main.png', 100)
        self.log_msg("已进入游戏主界面")

        for i in range(1):
            self.log_msg("检查是否存在弹窗")
            self.game_alert()

            self.img_click_if_exists("点击前行游戏", './game/img/小鸡舰队出击/play.png', './game/img/小鸡舰队出击/play01.png')
            self.log_msg("滑动到最左")
            self.swipe_right()
            self.swipe_right()
            self.log_msg("点击开始游戏")
            self.img_click('./game/img/小鸡舰队出击/play01.png')
            self.log_msg("等待进入战斗界面")
            self.img_exit('./game/img/小鸡舰队出击/play_main.png')
            self.log_msg("进入战斗界面")
            while True:
                if self.img_click("./game/img/小鸡舰队出击/win.png", 3):
                    self.log_msg("战斗胜利")
                    break

                self.select()

                self.log_msg("检查是否存在卡片")
                if self.img_click("./game/img/小鸡舰队出击/play01.png", 3):
                    self.log_msg("点击鸡蛋")
                    continue
                if self.img_click("./game/img/小鸡舰队出击/play02.png", 3):
                    self.log_msg("点击羽毛")
                    continue
                self.d.sleep(10)
            self.log_msg("点击确定")
            self.img_click('./game/img/小鸡舰队出击/play_done.png')
        # self.d.sleep(2)
#        self.close_game()
